const btn = document.querySelector('#btn-goto-view')
const app = document.querySelector('#app-container')


window.addEventListener("DOMContentLoaded", (e) => {
    console.log('init path', location.pathname)
    if (app === null) {
        console.warn("app container not found.")
        return
    }
    if (location.pathname === "/" || location.pathname === '/index') {
        app.innerHTML = "Index content";
    } else if (location.pathname === '/view') {
        app.innerHTML = "route view content"
    }
})

window.onpopstate = (e) => {
    console.log('onpopstate', e.state, location.pathname);
}

btn?.addEventListener('click', function () {
    const state = {
        pathName: 'view'
    }
    history.pushState(state, "", "view")
})